home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 52
/
Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso
/
Aminet
/
misc
/
emu
/
Apex-src.lha
/
SERHAN.68K
< prev
next >
Wrap
Text File
|
2001-09-30
|
6KB
|
194 lines
;SERHAN.68K JAN-15-86 (ALSO SEE "INFOSTR")
;RS-232 HANDLER
;WRITTEN BY LOREN BLANEY
;
;REVISION HISTORY:
;
;NOTES:
;This uses serial port #2, 9600 baud, no handshake, 8 data bits, 1 stop
; bit, and no parity.
NOLIST
INCLUDE SYSPAG ;GET THE SYSTEM PAGE DIFINITIONS
LIST
DEVNUM EQU 4 ;INSTALL THIS HANDLER AS DEVICE # 4
;68681 DUART REGISTER I/O ADDRESSES:
URT0SRA EQU $FFC303 ;1 - STATUS REGISTER A FOR TERMINAL
URTMRXA EQU $FFC340 ;0 - MODE REGISTER A
URTSRA EQU $FFC343 ;1 - STATUS REGISTER A
URTCSRA EQU $FFC343 ;1 - CLOCK-SELECT REGISTER
URTCRA EQU $FFC345 ;2 - COMMAND REGISTER A
URTDTA EQU $FFC347 ;3 - TRANSMIT/RECEIVE DATA REGISTER
URTACR EQU $FFC349 ;4 - AUXILLARY CONTROL REGISTER
URTIMR EQU $FFC34B ;5 - INTERRUPT MASK REGISTER
PPAR11 EQU $FFC201 ;GENERAL OUTPUT PORT, LED RED +
ORG MEMTOP -$0700
START EQU @ ;ADDRESS WHERE THIS HANDLER STARTS
;=======================================================================
;ENTRY POINTS:
;
SERHAN DC.L OPENI ;$00 = OPENI
DC.L OPENO ;$04 = OPENO
DC.L CHIN ;$08 = CHIN
DC.L CHOUT ;$0C = CHOUT
DC.L CLOSE ;$10 = CLOSE
DC.L GETINFO ;$14 = GETINFO
DC.L DUMMY ;$18 = SPARE
DC.L DUMMY ;$1C = SPARE
;-----------------------------------------------------------------------
;OPEN (INITIALIZE) THE RS-232 PORT
;
OPENI BSR OPEN ;INIT RS-232 PORT FOR I/O, SET BAUD RATE
BSR FLUSH
DUMMY RTS
;-----------------------------------------------------------------------
;OPEN (INITIALIZE) THE RS-232 PORT
;
OPENO BSR OPEN ;INIT RS-232 PORT FOR I/O, SET BAUD RATE
BSR FLUSH
RTS
;-----------------------------------------------------------------------
;GET A CHARACTER FROM THE RS-232 PORT AND RETURN IT IN D0.
;
CHIN BSR BYTEIN
BEQ.S CHIN ;LOOP UNTIL A BYTE IS RECEIVED
RTS
;-----------------------------------------------------------------------
;OUTPUT THE BYTE IN D0 TO THE RS-232 PORT
;
CHOUT BSR BYTEOT
RTS
;-----------------------------------------------------------------------
;CLOSE THE OUTPUT FILE
;
CLOSE RTS
;-----------------------------------------------------------------------
;RETURN THE ADDRESS OF THE INFORMATION ARRAY IN D0
;
GETINFO MOVE.L #INFO,D0
RTS
INFO DC.L START ;START AND END ADDRESSES OF THIS HANDLER
DC.L END
DC.L INFOSTR ;DESCRIPTION
INFOSTR ASCII 'SERHAN JAN-15-86 RS-232 handle'
DC.B 'r'+$80
;=======================================================================
;LOWEST LEVEL I/O ROUTINES:
;
;INITIALIZE THE RS-232 PORT (68681) FOR I/O
;
OPEN MOVE.L A6,-(SP) ;SAVE A6
LEA OPENTBL.L,A6 ;POINT TO INITIALIZATION TABLE
MOVE.B (A6)+,URTIMR.L ;DISABLE ALL INTERRUPTS
MOVE.B (A6)+,URTCRA.L ;RESET MR POINTER TO MR1
MOVE.B (A6)+,URTMRXA.L ;SET PARITY, BITS PER CHAR, ETC.
MOVE.B (A6)+,URTMRXA.L ;SET STOP BIT WIDTH
MOVE.B (A6)+,URTACR.L ;SELECT BAUD SET (1 OR 2) & TIMER SOURCE
MOVE.B (A6)+,URTCSRA.L ;SET TRANSMITTER AND RECEIVER CLOCKS
MOVE.B (A6)+,URTCRA.L ;ENABLE TRANSMITTER AND RECEIVER
MOVEA.L (SP)+,A6 ;RESTORE A6
RTS
;68681 INITIALIZATION TABLE:
OPENTBL DC.B $00 ;DISABLE ALL INTERRUPTS
DC.B $10 ;RESET PTR TO MR1A
DC.B $13 ;NO RTS, NO PARITY, 8 DATA BITS
DC.B $07 ;1 STOP BIT
DC.B $0F ;SELECT BAUD SET 1 AND
DC.B $BB ; SELECT 9600 KB
DC.B $05 ;ENABLE TRANSMITTER AND RECEIVER
;OTHER BAUD RATES MAY BE SET:
; RATE ACR CSRA
; 38.4K $0F $CC
; 19.2K $8F $CC
; 9600 $0F $BB
; 4800 $0F $99
; 2400 $0F $88
; 1200 $0F $66
; 600 $0F $55
; 300 $0F $44
;-----------------------------------------------------------------------
;FLUSH OUT ANY CHARACTERS IN THE RECEIVE FIFO
; THE 68681 WORKS IN MYSTEROUS AND UNDOCUMENTED WAYS. THIS MAKES NO
; SENSE ACCORDING TO THE 68681 DOCUMENTATION, BUT IT IS WHAT STRIDE
; USES IN THEIR PROM CODE.
;
FLUSH MOVE.L D0,-(SP) ;SAVE D0
MOVEQ #3,D0 ;THE 68681 IS QUADRUPLLY BUFFERED
FL10 BTST #0,URTSRA.L ;LOOP UNTIL FIFO IS EMPTY
BEQ.S FL20 ;BRANCH IF THERE IS NO CHARACTER
TST.B URTDTA.L ;EAT THE CHARACTER
FL20 DBF D0,FL10 ;LOOP 4 TIMES
MOVE.L (SP)+,D0 ;RESTORE D0
RTS
;-----------------------------------------------------------------------
;GET A BYTE FROM THE RS-232 PORT AND RETURN IT IN D0
; "EQ" STATUS IS RETURNED IF A TIMEOUT OCCURS.
;
BYTEIN BSET #3,PPAR11.L ;MAKE LED RED TO SHOW WE'RE WAITING
MOVEQ #3,D0 ;INIT TIMEOUT COUNTER FOR ABOUT 1 SECOND
SWAP D0 ;(STRIDE TRICK TO SAVE ONE WHOLE WORD!)
BYIN10 BTST #0,URT0SRA.L ;IS THERE A BYTE IN THE TERMINAL RECEIVE
BEQ.S BYIN20 ; FIFO? BRANCH IF NOT
; JSR VCHKUSR ;CHECK FOR CTRL-C, CTRL-S, AND CTRL-P
MOVE.L A6,-(SP) ;SAVE A6
MOVEA.W #$20,A6 ;SET "CHKUSR" FUNCTION CODE
MOVE.B DEVICE,-(SP) ;SAVE THE CURRENT DEVICE NUMBER
MOVE.B #1,DEVICE ;SET TO DEVICE # 1
JSR VDEVHAN ;DISPATCH TO "CHKUSR" ROUTINE
MOVE.B (SP)+,DEVICE ;RESTORE DEVICE NUMBER
MOVEA.L (SP)+,A6 ;RESTORE A6
BYIN20 BTST #0,URTSRA.L ;IS THERE A BYTE IN THE RS-232 RECEIVE
BNE.S BYIN30 ; FIFO? BRANCH IF YES -- GO READ BYTE
SUBQ.L #1,D0 ;ELSE TICK OFF THE TIMEOUT COUNTER
BNE.S BYIN10 ;LOOP BACK IF THERE IS STILL TIME LEFT
BCLR #3,PPAR11.L ;MAKE LED GREEN (AND SETS Z FLAG)
RTS ;TIMED OUT -- RETURN WITH "EQ" STATUS
BYIN30 BCLR #3,PPAR11.L ;MAKE LED GREEN
CLR.L D0 ;CLEAR ANY GARBAGE IN THE UPPER BYTES
MOVE.B URTDTA.L,D0 ;GET THE BYTE
ANDI.B #$FB,CCR ;MAKE SURE Z FLAG IS CLEAR (NE)
RTS
;-----------------------------------------------------------------------
;SEND THE BYTE IN D0 OUT THE RS-232 PORT
BYTEOT BSET #3,PPAR11.L ;MAKE LED RED TO SHOW WE'RE WAITING
BYOT10 BTST #3,URTSRA.L ;WAIT FOR TRANSMITTER BUFFER EMPTY
BEQ.S BYOT10
BCLR #3,PPAR11.L ;MAKE LED GREEN
MOVE.B D0,URTDTA.L ;OUTPUT DATA
RTS
END EQU @ ;ADDRESS WHERE THIS HANDLER ENDS +1
;-----------------------------------------------------------------------
;HOOK THIS HANDLER INTO THE DEVICE HANDLER TABLE
;
ORG 4 *DEVNUM +DEVTBL
DC.L SERHAN
END
--------------------------
;HOOK THIS HAND